Added a "position" argument.
authorFederico Mena Quintero <federico@ximian.com>
Fri, 27 Feb 2004 20:48:22 +0000 (20:48 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Fri, 27 Feb 2004 20:48:22 +0000 (20:48 +0000)
2004-02-27  Federico Mena Quintero  <federico@ximian.com>

* gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
"position" argument.

* gtk/gtkfilesystem.h (GtkFileSystemError): Added value for
GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
(struct _GtkFileSystemIface): Added a "position" argument to the
::insert_bookmark() method.

* gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
an error if the path already exists in the bookmarks list.
(gtk_file_system_unix_remove_bookmark): Return an error if the
path does not exist in the bookmarks list.

* gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
For now, use gtk_file_system_insert_bookmark() with -1 for the
position.  DnD will come next.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdefault.c
gtk/gtkfilesystem.c
gtk/gtkfilesystem.h
gtk/gtkfilesystemunix.c

index 6187b603fa067ed336b473a9c6a3d09d9b1e9c66..06e3b77e98e67ab2ec9f8adc27388739b0cd53c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2004-02-27  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
+       "position" argument.
+
+       * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for 
+       GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
+       (struct _GtkFileSystemIface): Added a "position" argument to the
+       ::insert_bookmark() method.
+
+       * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
+       Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
+       an error if the path already exists in the bookmarks list.
+       (gtk_file_system_unix_remove_bookmark): Return an error if the
+       path does not exist in the bookmarks list.
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
+       For now, use gtk_file_system_insert_bookmark() with -1 for the
+       position.  DnD will come next.
+
 Fri Feb 27 21:42:28 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c (gtk_combo_box_relayout): 
index 6187b603fa067ed336b473a9c6a3d09d9b1e9c66..06e3b77e98e67ab2ec9f8adc27388739b0cd53c4 100644 (file)
@@ -1,3 +1,23 @@
+2004-02-27  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
+       "position" argument.
+
+       * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for 
+       GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
+       (struct _GtkFileSystemIface): Added a "position" argument to the
+       ::insert_bookmark() method.
+
+       * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
+       Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
+       an error if the path already exists in the bookmarks list.
+       (gtk_file_system_unix_remove_bookmark): Return an error if the
+       path does not exist in the bookmarks list.
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
+       For now, use gtk_file_system_insert_bookmark() with -1 for the
+       position.  DnD will come next.
+
 Fri Feb 27 21:42:28 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c (gtk_combo_box_relayout): 
index 6187b603fa067ed336b473a9c6a3d09d9b1e9c66..06e3b77e98e67ab2ec9f8adc27388739b0cd53c4 100644 (file)
@@ -1,3 +1,23 @@
+2004-02-27  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
+       "position" argument.
+
+       * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for 
+       GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
+       (struct _GtkFileSystemIface): Added a "position" argument to the
+       ::insert_bookmark() method.
+
+       * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
+       Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
+       an error if the path already exists in the bookmarks list.
+       (gtk_file_system_unix_remove_bookmark): Return an error if the
+       path does not exist in the bookmarks list.
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
+       For now, use gtk_file_system_insert_bookmark() with -1 for the
+       position.  DnD will come next.
+
 Fri Feb 27 21:42:28 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c (gtk_combo_box_relayout): 
index 6187b603fa067ed336b473a9c6a3d09d9b1e9c66..06e3b77e98e67ab2ec9f8adc27388739b0cd53c4 100644 (file)
@@ -1,3 +1,23 @@
+2004-02-27  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
+       "position" argument.
+
+       * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for 
+       GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
+       (struct _GtkFileSystemIface): Added a "position" argument to the
+       ::insert_bookmark() method.
+
+       * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
+       Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
+       an error if the path already exists in the bookmarks list.
+       (gtk_file_system_unix_remove_bookmark): Return an error if the
+       path does not exist in the bookmarks list.
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
+       For now, use gtk_file_system_insert_bookmark() with -1 for the
+       position.  DnD will come next.
+
 Fri Feb 27 21:42:28 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c (gtk_combo_box_relayout): 
index 6187b603fa067ed336b473a9c6a3d09d9b1e9c66..06e3b77e98e67ab2ec9f8adc27388739b0cd53c4 100644 (file)
@@ -1,3 +1,23 @@
+2004-02-27  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a
+       "position" argument.
+
+       * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for 
+       GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.
+       (struct _GtkFileSystemIface): Added a "position" argument to the
+       ::insert_bookmark() method.
+
+       * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark):
+       Updated; renamed from gtk_file_system_unix_add_bookmark().  Return
+       an error if the path already exists in the bookmarks list.
+       (gtk_file_system_unix_remove_bookmark): Return an error if the
+       path does not exist in the bookmarks list.
+
+       * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path):
+       For now, use gtk_file_system_insert_bookmark() with -1 for the
+       position.  DnD will come next.
+
 Fri Feb 27 21:42:28 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkcombobox.c (gtk_combo_box_relayout): 
index 47012301a644e41b9f2152b0892acd0582092574..5055850463a35be01d630e496464fb6ae37b84e5 100644 (file)
@@ -1232,7 +1232,7 @@ shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
   else
     {
       error = NULL;
-      if (!gtk_file_system_add_bookmark (impl->file_system, path, &error))
+      if (!gtk_file_system_insert_bookmark (impl->file_system, path, -1, &error))
        error_could_not_add_bookmark_dialog (impl, path, error);
     }
 }
index 248017c728187035e5efb5a403176dd75b281411..8be7443bbfd395e783441af37884550ed94f8081 100644 (file)
@@ -665,36 +665,46 @@ gtk_file_system_render_icon (GtkFileSystem      *file_system,
 }
 
 /**
- * gtk_file_system_add_bookmark:
+ * gtk_file_system_insert_bookmark:
  * @file_system: a #GtkFileSystem
- * @bookmark: path of the bookmark to add
+ * @path: path of the bookmark to add
+ * @position: index in the bookmarks list at which the @path should be inserted; use 0
+ * for the beginning, and -1 or the number of bookmarks itself for the end of the list.
  * @error: location to store error, or %NULL
  * 
- * Adds a bookmark folder to the user's bookmarks list.  If the operation succeeds,
- * the "bookmarks_changed" signal will be emitted.
+ * Adds a path for a folder to the user's bookmarks list.  If the operation
+ * succeeds, the "bookmarks_changed" signal will be emitted.  Bookmark paths are
+ * unique; if you try to insert a @path that already exists, the operation will
+ * fail and the @error will be set to #GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS.  To
+ * reorder the list of bookmarks, use gtk_file_system_remove_bookmark() to
+ * remove the path in question, and call gtk_file_system_insert_bookmark() with
+ * the new position for the path.
  * 
  * Return value: TRUE if the operation succeeds, FALSE otherwise.  In the latter case,
  * the @error value will be set.
  **/
 gboolean
-gtk_file_system_add_bookmark (GtkFileSystem     *file_system,
-                             const GtkFilePath *path,
-                             GError           **error)
+gtk_file_system_insert_bookmark (GtkFileSystem     *file_system,
+                                const GtkFilePath *path,
+                                gint               position,
+                                GError           **error)
 {
   g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
   g_return_val_if_fail (path != NULL, FALSE);
 
-  return GTK_FILE_SYSTEM_GET_IFACE (file_system)->add_bookmark (file_system, path, error);
+  return GTK_FILE_SYSTEM_GET_IFACE (file_system)->insert_bookmark (file_system, path, position, error);
 }
 
 /**
  * gtk_file_system_remove_bookmark:
  * @file_system: a #GtkFileSystem
- * @bookmark: path of the bookmark to remove
+ * @path: path of the bookmark to remove
  * @error: location to store error, or %NULL
  * 
  * Removes a bookmark folder from the user's bookmarks list.  If the operation
- * succeeds, the "bookmarks_changed" signal will be emitted.
+ * succeeds, the "bookmarks_changed" signal will be emitted.  If you try to remove
+ * a @path which does not exist in the bookmarks list, the operation will fail
+ * and the @error will be set to GTK_FILE_SYSTEM_ERROR_NONEXISTENT.
  * 
  * Return value: TRUE if the operation succeeds, FALSE otherwise.  In the latter
  * case, the @error value will be set.
index 3dc914b2c95a2d6a08d8df86ce051bb9d708e81a..8503ff1ea00360dc271f48e11dd1e138222d03fc 100644 (file)
@@ -70,6 +70,7 @@ typedef enum
   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
   GTK_FILE_SYSTEM_ERROR_FAILED,
+  GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS
 } GtkFileSystemError;
 
 GQuark     gtk_file_system_error_quark      (void);
@@ -185,8 +186,9 @@ struct _GtkFileSystemIface
 
   /* Bookmarks */
 
-  gboolean       (*add_bookmark)           (GtkFileSystem     *file_system,
+  gboolean       (*insert_bookmark)        (GtkFileSystem     *file_system,
                                            const GtkFilePath *path,
+                                           gint               position,
                                            GError           **error);
   gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
                                            const GtkFilePath *path,
@@ -260,8 +262,9 @@ GdkPixbuf   *gtk_file_system_render_icon   (GtkFileSystem      *file_system,
                                            gint                pixel_size,
                                            GError            **error);
 
-gboolean gtk_file_system_add_bookmark    (GtkFileSystem     *file_system,
+gboolean gtk_file_system_insert_bookmark (GtkFileSystem     *file_system,
                                          const GtkFilePath *path,
+                                         gint               position,
                                          GError           **error);
 gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
                                          const GtkFilePath *path,
index 0117ab335ffff9727d12d749bdab14cd18d367f5..2becd2dfebbd159435419d9faa1f1e2a3ffdb550 100644 (file)
@@ -160,8 +160,9 @@ static GdkPixbuf *gtk_file_system_unix_render_icon (GtkFileSystem     *file_syst
                                                    gint               pixel_size,
                                                    GError           **error);
 
-static gboolean gtk_file_system_unix_add_bookmark    (GtkFileSystem     *file_system,
+static gboolean gtk_file_system_unix_insert_bookmark (GtkFileSystem     *file_system,
                                                      const GtkFilePath *path,
+                                                     gint               position,
                                                      GError           **error);
 static gboolean gtk_file_system_unix_remove_bookmark (GtkFileSystem     *file_system,
                                                      const GtkFilePath *path,
@@ -275,7 +276,7 @@ gtk_file_system_unix_iface_init   (GtkFileSystemIface *iface)
   iface->uri_to_path = gtk_file_system_unix_uri_to_path;
   iface->filename_to_path = gtk_file_system_unix_filename_to_path;
   iface->render_icon = gtk_file_system_unix_render_icon;
-  iface->add_bookmark = gtk_file_system_unix_add_bookmark;
+  iface->insert_bookmark = gtk_file_system_unix_insert_bookmark;
   iface->remove_bookmark = gtk_file_system_unix_remove_bookmark;
   iface->list_bookmarks = gtk_file_system_unix_list_bookmarks;
 }
@@ -1069,11 +1070,13 @@ bookmark_list_write (GSList *bookmarks, GError **error)
 }
 
 static gboolean
-gtk_file_system_unix_add_bookmark (GtkFileSystem     *file_system,
-                                  const GtkFilePath *path,
-                                  GError           **error)
+gtk_file_system_unix_insert_bookmark (GtkFileSystem     *file_system,
+                                     const GtkFilePath *path,
+                                     gint               position,
+                                     GError           **error)
 {
   GSList *bookmarks;
+  int num_bookmarks;
   GSList *l;
   char *uri;
   gboolean result;
@@ -1087,6 +1090,9 @@ gtk_file_system_unix_add_bookmark (GtkFileSystem     *file_system,
       return FALSE;
     }
 
+  num_bookmarks = g_slist_length (bookmarks);
+  g_return_val_if_fail (position >= -1 && position <= num_bookmarks, FALSE);
+
   result = FALSE;
 
   uri = gtk_file_system_unix_path_to_uri (file_system, path);
@@ -1097,19 +1103,25 @@ gtk_file_system_unix_add_bookmark (GtkFileSystem     *file_system,
 
       bookmark = l->data;
       if (strcmp (bookmark, uri) == 0)
-       break;
+       {
+         g_set_error (error,
+                      GTK_FILE_SYSTEM_ERROR,
+                      GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS,
+                      "%s already exists in the bookmarks list",
+                      uri);
+         goto out;
+       }
     }
 
-  if (!l)
+  bookmarks = g_slist_insert (bookmarks, g_strdup (uri), position);
+  if (bookmark_list_write (bookmarks, error))
     {
-      bookmarks = g_slist_append (bookmarks, g_strdup (uri));
-      if (bookmark_list_write (bookmarks, error))
-       {
-         result = TRUE;
-         g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
-       }
+      result = TRUE;
+      g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
     }
 
+ out:
+
   g_free (uri);
   bookmark_list_free (bookmarks);
 
@@ -1139,27 +1151,32 @@ gtk_file_system_unix_remove_bookmark (GtkFileSystem     *file_system,
 
       bookmark = l->data;
       if (strcmp (bookmark, uri) == 0)
-       break;
-    }
+       {
+         g_free (l->data);
+         bookmarks = g_slist_remove_link (bookmarks, l);
+         g_slist_free_1 (l);
 
-  if (l)
-    {
-      g_free (l->data);
-      bookmarks = g_slist_remove_link (bookmarks, l);
-      g_slist_free_1 (l);
+         if (bookmark_list_write (bookmarks, error))
+           {
+             result = TRUE;
+             g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
+           }
 
-      if (bookmark_list_write (bookmarks, error))
-       result = TRUE;
+         goto out;
+       }
     }
-  else
-    result = TRUE;
+
+  g_set_error (error,
+              GTK_FILE_SYSTEM_ERROR,
+              GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
+              "%s does not exist in the bookmarks list",
+              uri);
+
+ out:
 
   g_free (uri);
   bookmark_list_free (bookmarks);
 
-  if (result)
-    g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
-
   return result;
 }